//
//  KARepayDetailPeriodCell.swift
//  kano
//
//  Created by Frank on 2024/9/19.
//

import UIKit

class KARepayDetailPeriodCell: UITableViewCell {
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        self.contentView.backgroundColor = .white
    }
    
    lazy var var_bgView: UIView = {
        let var_bgView = UIView();
        var_bgView.backgroundColor = .colorf2f2f5
        return var_bgView
    }()
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.numberOfLines = 1
        label.font = UIFont.systemFont(ofSize: kscale(13), weight: .bold)
        label.textColor = .color323135
        label.text = ""
        return label
    }()
    lazy var amountLabel: UILabel = {
        let label = UILabel()
        label.numberOfLines = 1
        label.font = UIFont.systemFont(ofSize: kscale(13), weight: .bold)
        label.textColor = .color323135
        label.text = ""
        return label
    }()
    
    lazy var var_selectImg: UIImageView = {
        let var_selectImg = UIImageView(image: UIImage(named: "repay_unsel"))
        return var_selectImg
    }()
    lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.numberOfLines = 1
        label.font = UIFont.systemFont(ofSize: kscale(13), weight: .bold)
        label.textColor = .colorAEACB3
        label.text = ""
        return label
    }()
    
    static func ka_cell(for tableView: UITableView) -> KARepayDetailPeriodCell {
        let var_identifityId = NSStringFromClass(self)
        var var_cell = tableView.dequeueReusableCell(withIdentifier: var_identifityId)
        if var_cell == nil {
            var_cell = KARepayDetailPeriodCell.init(style: .default, reuseIdentifier: var_identifityId)
        }
        return var_cell as! KARepayDetailPeriodCell
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        ka_setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var topCorner: Bool = false
    var bottomCorner: Bool = false
}

extension KARepayDetailPeriodCell: UITextFieldDelegate {
    func ka_setUI() {
        backgroundColor = .white
        contentView.addSubview(var_bgView)
        var_bgView.addSubview(titleLabel)
        var_bgView.addSubview(amountLabel)
        var_bgView.addSubview(var_selectImg)
        var_bgView.addSubview(contentLabel)

    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        var_bgView.snp.makeConstraints { make in
            make.top.bottom.equalTo(contentView)
            make.left.equalTo(contentView).offset(kscale(16));
            make.right.equalTo(contentView).offset(kscale(-16));
        }
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(var_bgView).offset(kscale(10));
            make.centerY.equalTo(var_bgView);
        }
        amountLabel.snp.makeConstraints { make in
            make.center.equalTo(var_bgView);
        }
        var_selectImg.snp.makeConstraints { make in
            make.right.equalTo(var_bgView).offset(kscale(-10));
            make.size.equalTo(CGSizeMake(kscale(16), kscale(16)))
            make.centerY.equalTo(var_bgView);
        }
        contentLabel.snp.makeConstraints { make in
            make.right.equalTo(var_selectImg.snp.left).offset(kscale(-8));
            make.centerY.equalTo(var_bgView);
        }
        
        if (topCorner && bottomCorner) {
            var_bgView.ka_addCorner(withRadius: kscale(10))
        } else {
            if (topCorner) {
                var_bgView.ka_addTopCorner(withRadius: kscale(10))
            }
            if (bottomCorner) {
                var_bgView.ka_addBottomCorner(withRadius: kscale(10))
            }
        }
    }
}

